<?php

class ImportXMLEtudiant
{
	
	private $xml;
	private $url;
	
	private $position;
	
	private $raccourci;
	
	
	private $num_etu;
	private $nom;
	private $prenom;
	private $login;
	private $section;
	private $promotion;
	
	private $pass;
	
	
	public function ImportXMLEtudiant($url,$num){
		
		$this->url = $url;
		$this->position = $num;
		$this->get_contents();
		
	}
	
	public function get_contents()
	{
		$rss_file = file_get_contents($this->url);
		$this->xml = new SimpleXMLElement($rss_file);
	
	}
	
	public function setRaccourci()
	{
		$this->raccourci = $this->xml->LIST_G_CGE[0]->G_CGE[0]->LIST_G_ETP[0]->G_ETP[0]->LIST_G_VET[0]->G_VET[0]->LIST_G_CMP[0]->G_CMP[0]->LIST_G_IAE[0]->G_IAE[$this->position];
	}
	
	public function getNumEtu()
	{
		$this->num_etu = $this->raccourci->COD_ETU[0];
		$this->nom = $this->raccourci->LIB_NOM_PAT_IND[0];
		$this->prenom = $this->raccourci->LIB_PR1_IND[0];
		
		
		$nomTronque = str_replace(' ','',$this->nom);
		$nomTronque = substr($nomTronque,0,8);
		
		$this->login = strtolower(substr($this->prenom,0,1).$nomTronque);
		$this->pass = strtolower($nomTronque);
		
		$this->promotion = $this->xml->LIST_G_CGE[0]->G_CGE[0]->LIST_G_ETP[0]->G_ETP[0]->COD_ETP1[0];
		$this->section = addslashes($this->xml->LIST_G_CGE[0]->G_CGE[0]->LIST_G_ETP[0]->G_ETP[0]->LIB_ETP[0]);
	}
	
	public function getNom()
	{
		
	}
	
	public function getPrenom()
	{
		
	}
	
	public function genereLogin()
	{
		
	}
	
	public function getPromotion()
	{
		
	}
	
	public function getSection()
	{
		
	}
	
	public function insereBDD()
	{
		
		$req = "INSERT INTO utilisateur VALUES ('','".$this->nom."',
													'".$this->prenom."',
													'',
													'',
													'".$this->login."',
													'".$this->pass."',
													1);";
		
		$requeteInsert1 = new RequeteSQL($req);
		
		$requeteInsert1->executeEcriture();
		
		$reqRecupNumEtu = "SELECT uti_num_user FROM utilisateur WHERE uti_login = '".$this->login."';";
		
		$requeteRecupNumEtu = new RequeteSQL($reqRecupNumEtu);
		
		$requeteRecupNumEtu->executeQuery();
		$resRecupNumEtu = $requeteRecupNumEtu->fetch();
		
		//echo $resRecupNumEtu['uti_num_user'];
		
		$reqInsert2 = "INSERT INTO etudiant VALUES (".$resRecupNumEtu['uti_num_user'].",
														".$this->num_etu.",
														'',
														'".$this->section."',
														'".$this->promotion."',
														'','');";
		
		$requeteInsert2 = new RequeteSQL($reqInsert2);
		
		$requeteInsert2->executeEcriture();
	}
	
	public function getNbEtuAImport()
	{
		
		return count($this->xml->LIST_G_CGE[0]->G_CGE[0]->LIST_G_ETP[0]->G_ETP[0]->LIST_G_VET[0]->G_VET[0]->LIST_G_CMP[0]->G_CMP[0]->LIST_G_IAE[0]->G_IAE);
	}
	
	public function next()
	{
		$this->position++;
	}
	
}





?>